package cn.xo68.ide.plugin.common;

import com.intellij.openapi.vfs.VirtualFile;

import java.io.File;
import java.util.Properties;

/**
 * 插件路径工具集
 */
public final class PluginPathUtils {

    /**
     * 插件数据目录
     */
    public static String KEY_PLUGIN_DATA_PATH="wts.data.path";
    /**
     * 日志目录
     */
    public static String KEY_PLUGIN_LOG_PATH="wts.log.path";

    public static String KEY_PLUGIN_STORE_PATH="wts.store.path";

    /**
     * 插件数据文件夹名
     */
    public static String IDE_PLUGIN_DATA_FOLDER="wtsdata";

    public static String IDE_PLUGIN_LOG_FOLDER="log";

    public static String IDE_PLUGIN_STORE_FOLDER="store";

    public static String IDE_PLUGIN_TEMPLATE_FOLDER="template";

    private static Properties getSystemProperties(){
        return System.getProperties();
    }

    /**
     * 插件数据根目录
     * @return
     */
    public static String getDataPath(){
        return getSystemProperties().getProperty(KEY_PLUGIN_DATA_PATH);
    }

    public static void setDataPath(String path){
        getSystemProperties().put(KEY_PLUGIN_DATA_PATH, path);
    }

    /**
     * 日志目录
     * @return
     */
    public static String getLogPath(){
        return getDataPath() + File.separator + IDE_PLUGIN_LOG_FOLDER;
    }
    public static void setLogPath(String path){
        getSystemProperties().put(KEY_PLUGIN_LOG_PATH, path);
    }

    /**
     * 存储
     * @return
     */
    public static String getStorePath(){
        return getDataPath() + File.separator + IDE_PLUGIN_STORE_FOLDER;
    }
    public static void setStorePath(String path){
        getSystemProperties().put(KEY_PLUGIN_STORE_PATH, path);
    }

    public static String getTemplatePath(){
        return getStorePath() + File.separator + IDE_PLUGIN_TEMPLATE_FOLDER;
    }

    /**
     * 代码生成配置的原始路径
     * @return
     */
    public static String getCodeGenerateConfigPath(){
        return getStorePath() + File.separator + PluginConstants.GENERATE_CONFIG_NAME;
    }

    /**
     * 代码生成配置文件路径
     * @param virtualFile
     * @return
     */
    public static String getCodeGenereateConfigPath(VirtualFile virtualFile){
        return virtualFile.getCanonicalPath() + File.separator + PluginConstants.GENERATE_CONFIG_NAME;
    }

    public static String getCodeGenereateInfoDir(VirtualFile virtualFile){
        return virtualFile.getCanonicalPath() + File.separator + PluginConstants.GENERATE_DIRECTORY;
    }
    public static String getCodeGenereateInfoPath(VirtualFile virtualFile){
        return getCodeGenereateInfoDir(virtualFile) + File.separator + PluginConstants.GENERATE_CODE_INFO_FILE;
    }
    public static String getDatabaseMetaDataPath(VirtualFile virtualFile){
        return getCodeGenereateInfoDir(virtualFile) + File.separator + PluginConstants.GENERATE_METADATA_FILE;
    }

    public static String getTableModuleConfigPath(VirtualFile virtualFile){
        return getCodeGenereateInfoDir(virtualFile) + File.separator + PluginConstants.GENERATE_METADATA_MODULE_FILE;
    }
}
